package com.bawei.module_login.view.activity

import android.view.View
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter
import androidx.viewpager.widget.ViewPager.OnPageChangeListener
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bawei.module_base.ui.base.BaseActivity
import com.bawei.module_base.ui.base.BaseViewModel
import com.bawei.module_login.R
import com.bawei.module_login.databinding.ActivityReversoContextBinding
import com.bawei.module_login.view.fragment.ConstellationFragment
import com.bawei.module_login.view.fragment.GenderFragment
import com.bawei.module_login.view.fragment.LabelFragment


@Route(path = "/reverso/context_activity")
class ReversoContextActivity : BaseActivity<BaseViewModel, ActivityReversoContextBinding>() {
    private val fragments=ArrayList<Fragment>()

    override fun getLayout(): Int {
        return R.layout.activity_reverso_context
    }

    override fun initData() {
        initViewPage()
        binding.reversoTiao.setOnClickListener(View.OnClickListener {
            ARouter.getInstance().build("/main/main_activity").navigation()
            finish()
        })
    }
    fun initViewPage(){
        fragments.add(GenderFragment())
        fragments.add(ConstellationFragment())
        fragments.add(LabelFragment())
        //Viewpage中放入布局
        binding.reversoVp.adapter=object :FragmentPagerAdapter(supportFragmentManager){
            override fun getCount(): Int {
                return fragments.size
            }

            override fun getItem(position: Int): Fragment {
                return fragments[position]
            }

        }
        //联动 切换时改变
        binding.reversoVp.setOnPageChangeListener(object :OnPageChangeListener{
            override fun onPageScrolled(
                position: Int,
                positionOffset: Float,
                positionOffsetPixels: Int
            ) {
            }

            override fun onPageSelected(position: Int) {
                //设置下标
                binding.stripTablayout.setStep(position)
            }

            override fun onPageScrollStateChanged(state: Int) {

            }

        })
        binding.stripTablayout.setPageChangeListener {
            //布局和点击切换呼应
            binding.reversoVp.currentItem=it
        }

        binding.reversoTiao.setOnClickListener(View.OnClickListener {
            ARouter.getInstance().build("/main/main_activity").navigation()
            finish()
        })

    }


    override fun getViewModelClass(): Class<BaseViewModel> {
       return BaseViewModel::class.java
    }

}